﻿@page "/Page1"

<h3>Page1</h3>

@*<div>组件的数据绑定</div>

    <ul>
        <li>参数赋值即单向</li>
        <li>@@bind-Field 展开 Field 与 FieldChanged</li>
        <li>数据双向绑定导致的性能问题</li>
    </ul>*@

<p>Name: @Model.Name</p>

<FooBind Field="@Model.Name" />

@*<FooBind Field="@Model.Name" FieldChanged="@OnFieldChanged" />*@

@*<Select @bind-Value="Order" OnSelectedItemChanged="OnItemChanged" />

<span>@OrderString</span>*@

@code {
    private class Foo
    {
        public string Name { get; set; }
    }

    private Foo Model { get; set; }

    private SortOrder Order { get; set; }

    private string OrderString { get; set; }

    /// <summary>
    ///
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Model = new Foo() { Name = "张三" };
    }

    private void OnFieldChanged(string val)
    {
        Model.Name = val;
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
    }

    private Task OnItemChanged(SelectedItem item)
    {
        OrderString = item.Value;
        return Task.CompletedTask;
    }
}
